function getUrlParms(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
  var r = window.location.search.substr(1).match(reg)
  if (r != null) return decodeURI(r[2])
  return null
}
let id = getUrlParms("id")

if (!id || !localStorage.getItem(id)) {
  window.location.href = "/view/questionnaire-list/questionnaire-list.html"
}

let questionnaire = JSON.parse(localStorage.getItem(id))

let questionList = questionnaire.questionList

document.getElementById("title").innerHTML = questionnaire.title

let questionContainer = document.querySelector(".question-container")

questionList.forEach((question, index) => {
  let questionItem = document.createElement("question-item")
  questionItem.setAttribute(
    "question",
    JSON.stringify({ index: index + 1, ...question })
  )
  questionContainer.appendChild(questionItem)
})
